package com.zyx.beancopy.copier;

import com.zyx.beancopy.copier.mapper.MapStructCopier;
import com.zyx.beancopy.model.Source;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Component;

/**
 * @author Yaxi.Zhang
 * @since 2022/4/21 11:06
 * desc: 缺点是需要定义转换接口；优点是性能最高
 */
@Component
public class MapsCopier {

    private MapStructCopier mapStructCopier = Mappers.getMapper(MapStructCopier.class);

    public <K, T> T copy(K source, Class<T> target) {
        return (T) mapStructCopier.copy((Source) source);
    }

    public <T> T copyAndParse(Source source, Class<T> target) {
        return (T) mapStructCopier.copyAndParse(source);
    }
}
